
  		import mx.effects.Zoom; 
  		import mx.effects.Sequence; 
        import mx.events.*;
        import Math;
		//this script is used only for panning and zooming
  		private static var coef:Number = 1.4;//Coeficient of Zooming
  		private static var lastWidth:Number = 1;//last widht of the Image Map before Zooming
  		private static var lastHeight:Number = 1;//last height of the Image Map before Zooming
  		//these two vars show where the drag starts
  		private static var dragStartX : Number = 0;//this is on X coordinate
  		private static var dragStartY : Number = 0;//this is on Y coordinate
  		private static var isMouseDown : Boolean = false;//is mouse button pushed
  		
  		private static var nextPictureToBeLoadedNumber : Number = 1;//counter for current loaded picture
  		private static var currentPictureX : Number = -150;//these two vars defines added picture position
  		private static var currentPictureY : Number = 0;
  		private static var rightTo:Number = 2;//these 4 vars shows when we have to change direction of mooving
  		private static var upTo:Number = 3;
  		private static var leftTo:Number = 5;
  		private static var downTo:Number = 7;
  		private static var roundNumber:Number = 1;//round of the spiral
  		private static var moovingY:Number = 30;//displacement of picture on X
  		private static var moovingX:Number = 30;//displacement of picture on Y
  		private static var shuffleMovingMax = 10;//shuffleMoving < pictureSize - mooving
  		private static var pictureSize:Number = 20;//size of the Image control
  		private static var addX:Number = moovingX;//displacement of last put picture on X and on Y
  		private static var addY:Number = 0;
  		
  		// this method add picture to the cnvImageMap
  		public function AddPicture(img:FlickrImage):void
  		{
  			nextPictureToBeLoadedNumber++;
  			img.addEventListener(MouseEvent.CLICK, imageClickListener);
  			img.width = pictureSize;
  			img.height = pictureSize;
  			img.x = currentPictureX + Math.round(100*Math.random()) % shuffleMovingMax;
  			img.y = currentPictureY + Math.round(100*Math.random()) % shuffleMovingMax;
  			this.cnvImageMap.addChild(img);
  			currentPictureY += addY;
  			currentPictureX += addX;
  			if(nextPictureToBeLoadedNumber == rightTo)
  			{			
  				addX = 0;
  				addY = -moovingY;
  			}
  			else if(nextPictureToBeLoadedNumber == leftTo)
  			{			
  				addX = 0;
  				addY = moovingY;
  			}
  			else if(nextPictureToBeLoadedNumber == downTo)
  			{
  				addX = moovingX;
  				addY = 0;
  				rightTo += 8*roundNumber;
  				upTo = rightTo + 2*roundNumber + 1;
  				leftTo = rightTo + 4*roundNumber + 3;
  				downTo = rightTo + 6*roundNumber + 5;
  				roundNumber++;
  			}
  			else if(nextPictureToBeLoadedNumber == upTo)
  			{
  				addX = -moovingX;
  				addY = 0;		
  			}
  			return;
  		}
  		//function |modul|
  		private function abs(x:Number):Number
  		{
  			if(x > 0)
  			{
  				return x;
  			}
  			else
  			{
  				return -x;
  			}
  		}
		//keyboard handler
        private function keyHandler(event:KeyboardEvent):void {
            if(event.keyCode == 38)
            {
            	this.PanUp_Click(event);
            }
            else if(event.keyCode == 37)
            {
            	this.PanLeft_Click(event);
            }
            else if(event.keyCode == 39)
            {
            	this.PanRight_Click(event);
            }
            else if(event.keyCode == 40)
            {
            	this.PanDown_Click(event);
            }
	  		if(event.ctrlKey && event.keyCode == 109)
	  		{
	  		 	this.ZoomOut_Click(event);
	  		}
			if(event.ctrlKey && event.keyCode == 107)
	  		{
	  		 	this.ZoomIn_Click(event);
	  		}
        }

  		//Function for Zoom In
  		private function ZoomIn_Click(event:Event): void {
  			if(Zoom.isPlaying || Pan.isPlaying){
  				
  			}
  			else{
  				Zoom.zoomWidthFrom = lastWidth;
  				lastWidth *= coef;
  				Zoom.zoomWidthTo = lastWidth;
  				Zoom.zoomHeightFrom = lastHeight;
  				lastHeight *= coef;
  				Zoom.zoomHeightTo = lastHeight;
  				Zoom.play([cnvImageMap]);
  				Pan.xTo = cnvImageMap.x;
  				Pan.yTo = cnvImageMap.y;
  			}
  		}
  		//Function for Zoom Out
  		private function ZoomOut_Click(event:Event): void {
  			if(Zoom.isPlaying || Pan.isPlaying){
  				
  			}
  			else{
  				Zoom.zoomWidthFrom = lastWidth;
  				lastWidth /= coef;
  				Zoom.zoomWidthTo = lastWidth;
  				Zoom.zoomHeightFrom = lastHeight;
  				lastHeight /= coef;			
  				Zoom.zoomHeightTo = lastHeight;
  				Zoom.play([cnvImageMap]);
  				Pan.xTo = cnvImageMap.x;
  				Pan.yTo = cnvImageMap.y;
  			}
  		}
  		//All panes used in application
  		//Pan Right
  		private function PanRight_Click(event:Event): void {
  			if(Zoom.isPlaying || Pan.isPlaying){
  				
  			}
  			else{
  			Pan.yTo = cnvImageMap.y;
  			Pan.xTo = cnvImageMap.x - 200;
  			Pan.play([cnvImageMap]);
  			}
  		}
  		//Pan Left
  		private function PanLeft_Click(event:Event): void {
  			if(Zoom.isPlaying || Pan.isPlaying){
  				
  			}
  			else{
  			Pan.yTo = cnvImageMap.y;
  			Pan.xTo = cnvImageMap.x + 200;
  			Pan.play([cnvImageMap]);
  			}
  		}
  		//Pan Down
  		private function PanDown_Click(event:Event): void {
  			if(Zoom.isPlaying || Pan.isPlaying){
  				
  			}
  			else{
  			Pan.xTo = cnvImageMap.x;
  			Pan.yTo = cnvImageMap.y - 200;
  			Pan.play([cnvImageMap]);
  			}
  		}
  		//Pan Up
  		private function PanUp_Click(event:Event): void {
  			if(Zoom.isPlaying || Pan.isPlaying){
  				
  			}
  			else{
  				Pan.xTo = cnvImageMap.x;
  			Pan.yTo = cnvImageMap.y + 200;
  			Pan.play([cnvImageMap]);
  			}
  		}
  		//Pan Right and Down(south - eastern direction)
  		private function PanRightDown_Click(event:Event): void {
  			if(Zoom.isPlaying || Pan.isPlaying){
  				
  			}
  			else{
  			Pan.yTo = cnvImageMap.y - 200;
  			Pan.xTo = cnvImageMap.x - 200;
  			Pan.play([cnvImageMap]);
  			}
  		}
  		//Pan Right and Up(north - eastern direction)
  		private function PanRightUp_Click(event:Event): void {
  			if(Zoom.isPlaying || Pan.isPlaying){
  				
  			}
  			else{
  			Pan.yTo = cnvImageMap.y + 200;
  			Pan.xTo = cnvImageMap.x - 200;
  			Pan.play([cnvImageMap]);
  			}
  		}
  		//Pan Left and Up(north - western direction)
  		private function PanUpLeft_Click(event:Event): void {
  			if(Zoom.isPlaying || Pan.isPlaying){
  				
  			}
  			else{
  			Pan.yTo = cnvImageMap.y + 200;
  			Pan.xTo = cnvImageMap.x + 200;
  			Pan.play([cnvImageMap]);
  			}
  		}
  		//Pan Left and Down(south - western direction)
  		private function PanDownLeft_Click(event:Event): void {
  			if(Zoom.isPlaying || Pan.isPlaying){
  				
  			}
  			else{
  			Pan.yTo = cnvImageMap.y - 200;
  		  	Pan.xTo = cnvImageMap.x + 200;
  			Pan.play([cnvImageMap]);
  			}
  		}
  		//move Image Map to center of maincanvas
  		private function MoveCenter_Click(event:MouseEvent): void {
  			if(Zoom.isPlaying || Pan.isPlaying){
  				
  			}
  			else{
  			Pan.xTo = cnvMain.width/2 - cnvImageMap.width/2;
  			Pan.yTo = cnvMain.height/2 - cnvImageMap.height/2;
  			Pan.play([cnvImageMap]);
  			}
  		}
  		//these 3 eventHandlers are used for making drag effect on map
  		//this eventHanler set start dragging
  		private function Mouse_Down_Handler(event:MouseEvent): void {
  			if(Zoom.isPlaying || Pan.isPlaying){
  				
  			}
  			else{
			dragStartX = this.mouseX;
			dragStartY = this.mouseY;
			isMouseDown = true;
  			}
  		}
  		//this eventHanler set stop dragging
  		private function Mouse_Up_Handler(event:MouseEvent): void {
			isMouseDown = false;
  		}
  		//this eventHandler is realization of panning on the map.It also calculate the direction
  		private function Mouse_Move_Handler(event:MouseEvent):void{
  			if(isMouseDown)	
  			{
  				var left:Boolean = false;
  				var down:Boolean = false;
  				var up:Boolean = false;
  				var right:Boolean = false;
				
				if(abs(dragStartX - this.mouseX) > 1)//here we decide is this moving big enough
				{
	  				if(dragStartX > this.mouseX)	
	  				{
	  					left = false;
	  					right = true;
	  				}
	  				else if(dragStartX < this.mouseX)
	  				{
	  					left = true;
	  					right = false;
	  				}
  				}
  				if(abs(dragStartY - this.mouseY) > 1)//here we decide is this moving big enough
				{
	  				if(dragStartY < this.mouseY)	
	  				{
	  					up = true;
	  					down = false;
					}	
					else  if(dragStartY > this.mouseY)	
	  				{
	  					up = false;
	  					down = true;
					}
				}
  				
  				if(up)
  				{
  					if(right)
  					{
  						this.PanRightUp_Click(event);
  					}
  					else if(left)
  					{
  						this.PanUpLeft_Click(event);
  					}
  					else
  					{
  						this.PanUp_Click(event);
  					}
  				}
  				else if(down)
  				{
  					if(right)
  					{
  						this.PanRightDown_Click(event);
  					}
  					else if(left)
  					{
  						this.PanDownLeft_Click(event);
  					}
  					else
  					{
  						this.PanDown_Click(event);
  					}
  				}
  				else if(left)
  				{
  					this.PanLeft_Click(event);
  				}
  				else if(right)
  				{
  					this.PanRight_Click(event);
  				}
  				isMouseDown = false;//break panning
  			}
  		}
  		
  	//-------------------------------------------
		import mx.core.UIComponent;
		import flash.display.Shape;
		import flash.filters.GlowFilter;
		import mx.controls.Alert;
		static var focusedImage:Image;
		
            public function setFocusTo(object:UIComponent):void
            {
            	Alert.show("SET FOCUS TO");
                object.setFocus(); 
            }
            
            public function imageClickListener(e:MouseEvent):void{
            	
            	drawFocusTo(FlickrImage(e.currentTarget));
            }
            
            public function drawFocusTo(img:FlickrImage):void
            {              
            	var redGlow:GlowFilter = new GlowFilter(0xFF0000, 1, 30, 30, 1, 1, false, false);
            	var shadow:DropShadowFilter = new DropShadowFilter();
              img.filters = [redGlow];
              
              if(focusedImage == null){
              	img.setFocus();
              	imageFocusedEffect.play([img]);
              	focusedImage = img;
              	getPhotoInfo(img.photoId);
              }
              else if(focusedImage != img){                	
              	imageNotFocusedEffect.play([focusedImage]);
              	imageFocusedEffect.play([img]);
              	img.setFocus();
              	focusedImage.filters = [shadow];
              	focusedImage = img;
              	getPhotoInfo(img.photoId);
              }
              else {
                     	focusedImage.filters = [shadow];
                     	imageNotFocusedEffect.play([img]);
                     	focusedImage = null;
              }
            }
            private function checkKey(event:KeyboardEvent):void
            {
                if(event.charCode == 13)
                       searchPhotos();
            }